package org.mspring.mlog.web.admin;

import org.mspring.mlog.web.BaseAdminController;
import org.mspring.mlog.search.ArticleSearchService;
import org.mspring.nbee.web.support.WebContext;
import org.mspring.nbee.web.view.json.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Gao Youbo
 * @since 2015-11-06 13:24
 */
@Controller
@RequestMapping("/admin/article/search")
public class ArticleSearchController extends BaseAdminController {
    private ArticleSearchService articleSearchService;

    @RequestMapping("/index")
    @ResponseBody
    public JsonResult index(WebContext context, Model model) {
        long id = context.getRequiredLong("id");
        articleSearchService.addIndex(id);
        return JsonResult.getJsonResult(true);
    }

    @RequestMapping("/index-all")
    @ResponseBody
    public JsonResult indexAll(WebContext context, Model model) {
        articleSearchService.indexAll();
        return JsonResult.getJsonResult(true);
    }

    @Autowired
    public void setArticleSearchService(ArticleSearchService articleSearchService) {
        this.articleSearchService = articleSearchService;
    }

}
